package com.luxoft.scoremanager.server.model.web;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.luxoft.scoremanager.server.model.dao.ComponentValuesDaoModel;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import javax.persistence.*;
import java.io.Serializable;



public class Component implements Serializable {
    private static final long serialVersionUID = -5170875020617735653L;
    @Autowired
    private static Logger log = Logger.getLogger(Component.class);

    private Integer id;
    private Integer componentValuesId;
    private String label;
    private String existsValue;
    private String finalValue;
    private String staticData;

    public Component() {

    }

    public Component(ComponentValuesDaoModel componentValuesDaoModel) {
        if (componentValuesDaoModel.getComponentDao() != null ){
            this.id = componentValuesDaoModel.getComponentDao().getId();
            this.componentValuesId = componentValuesDaoModel.getId();
            this.label = componentValuesDaoModel.getComponentDao().getLabel();
            this.existsValue = componentValuesDaoModel.getExistsValue();
            this.finalValue = componentValuesDaoModel.getFinalValue();
            this.staticData = componentValuesDaoModel.getComponentDao().getStaticData();
        }
        else {
            log.info("DB error component dao doesn't exist but values id - " + componentValuesDaoModel.getId() + " exist");
        }
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Component component = (Component) o;

        if (id != null ? !id.equals(component.id) : component.id != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    public Component(Integer componentValuesId, String label, String existsValue, String finalValue, String staticData) {

        this.componentValuesId = componentValuesId;
        this.label = label;
        this.existsValue = existsValue;
        this.finalValue = finalValue;
        this.staticData = staticData;


    }

    public Component(Integer id, Integer componentValuesId, String label, String existsValue, String finalValue, String staticData) {

        this.id = id;
        this.componentValuesId = componentValuesId;
        this.label = label;
        this.existsValue = existsValue;
        this.finalValue = finalValue;
        this.staticData = staticData;

    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getComponentValuesId() {
        return componentValuesId;
    }

    public void setComponentValuesId(Integer componentValuesId) {
        this.componentValuesId = componentValuesId;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getExistsValue() {
        return existsValue;
    }

    public void setExistsValue(String existsValue) {
        this.existsValue = existsValue;
    }

    public String getFinalValue() {
        return finalValue;
    }

    public void setFinalValue(String finalValue) {
        this.finalValue = finalValue;
    }

    public String getStaticData() {
        return staticData;
    }

    public void setStaticData(String staticData) {
        this.staticData = staticData;
    }


    @Override
    public String toString() {
        return "Component{" +
                "id=" + id +
                ", scoreId=" + componentValuesId +
                ", label='" + label + '\'' +
                ", existsValue='" + existsValue + '\'' +
                ", finalValue='" + finalValue + '\'' +
                ", staticData='" + staticData + '\'' +
                '}';
    }


}